//应收结算/新增应收单

/**
 * 主视图
 */
interface ReceivableCloseAddViewModel extends ng.IScope {
    /**
     *应收编号
     */
    receivableId: string;
    /**
     *应收总编号
     */
    parentId: string;
    /**
     *应收说明
     */
    description: string;
    /**
     *增至应收账单
     */
    addReceivableTotle: () => void;

    back:()=>void
}


class ReceivableCloseAddController {

    constructor(private $scope: ReceivableCloseAddViewModel,
        private routeService: routeService,
        private receivableService: IReceivableService,
        private valueService: IValueService,
        private $state: angular.ui.IStateService,
        private $http: ng.IHttpService,
        private $location: ng.ILocationService, 
        private $ngBootbox: BootboxService) {
        this.init();
    }
    id;
    init(): void {
        
        this.$scope.receivableId  = this.$location.search().id;
        this.id=this.$location.search().code;
        this.$scope.parentId = "";
        this.$scope.description = "";

        this.$scope.addReceivableTotle = this.addReceivableTotle;

        this.$scope.back = this.back;
    }


    addReceivableTotle = () => {
        this.receivableService.toparent(this.id, this.$scope.parentId, this.$scope.description).then((res) => {
            this.$state.go("app.receivable.receivableClose");
        }, (rej) => { })
    }

    back=()=>{
        this.$state.go("app.receivable.receivableClose",{name:'receivableCloseList'});
    }

}

angular.module("tms").controller("receivableCloseAddController", ["$scope",
    "routeService",
    "receivableService",
    "valueService",
    "$state",
    "$http",
    "$location",
    "$ngBootbox", ReceivableCloseAddController]);



